<template>
  <div>
    <BorderView title="查获结果" />
    <el-table :data="chdjResultList">
      <el-table-column label="时间" align="center" prop="sj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sj, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="地点" align="center" prop="dd" />
      <el-table-column label="结果" align="center" prop="jg" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['user:sjsk:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >编辑</el-button
          >
          <el-button
            v-hasPermi="['user:sjsk:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div
      style="margin: 10px 0; text-align: center"
      @click="openChdjResultModal"
    >
      <el-button type="primary" size="mini" v-if="typeId">新增结果</el-button>
    </div>
    <ModalRef ref="reshultRef" @data-updated="loadChdjResults" />
  </div>
</template>
<script>
import BorderView from "@/views/components/BorderTitleView/index.vue";
import { getChdjResultById, delChdjResult } from "@/api/user/chdjResult";
import ModalRef from "./modal.vue";
export default {
  components: {
    BorderView,
    ModalRef,
  },
  props: {
    typeId: {
      type: String,
    },
  },
  data() {
    return {
      // 查获登记结果表格数据
      chdjResultList: [],
    };
  },
  watch: {
    typeId: {
      immediate: true,
      handler(newV) {
        if (newV) {
          this.families = [];
          this.loadChdjResults();
        }
      },
    },
  },
  methods: {
    openChdjResultModal() {
      this.$refs["reshultRef"].openModal(this.typeId);
    },
    loadChdjResults() {
      getChdjResultById(this.typeId).then((res) => {
        this.chdjResultList = res.data;
      });
    },
    handleUpdate(row) {
      this.$refs["reshultRef"].openModal(this.typeId, row.chdjResultId);
    },
    handleDelete(row) {
      const chdjResultIds = row.chdjResultId;
      this.$modal
        .confirm('是否确认删除编号为"' + chdjResultIds + '"的数据项？')
        .then(() => {
          return delChdjResult(chdjResultIds);
        })
        .then(() => {
          this.loadChdjResults();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {});
    },
  },
};
</script>
